﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PlayDeezGames.Common;
using System.Xml.Linq;

namespace DungeonDelver.Engine
{
    public class Item:Descriptor
    {
        public class Factory : IEntityFactory
        {
            public IEntity LoadFromXElement(IEntity theParent, System.Xml.Linq.XElement theXElement)
            {
                return new Item(theParent as MapCell, theXElement);
            }

            public IEntity Create(IEntity theParent)
            {
                return new Item(theParent as MapCell);
            }
            private Factory() { }

            public static void Register()
            {
                EntityFactories.RegisterFactory(Names.EngineFactories.ItemFactory, new Item.Factory());
            }
            public static void Unregister()
            {
                EntityFactories.UnregisterFactory(Names.EngineFactories.ItemFactory);
            }
        }

        private Item(MapCell theParent)
            : base(theParent)
        {
        }

        private Item(MapCell theParent, XElement theXElement) :
            base(theParent,theXElement)
        {
        }

        protected override XElement OnToXElement()
        {
            XElement result = new XElement(Names.EngineXNames.Item);
            result.Add(new XAttribute(PlayDeezGames.Common.Names.CommonXNames.Factory, Names.EngineFactories.ItemFactory));
            return result;
        }

        protected override void OnFromXElement(XElement theXElement)
        {
            base.OnFromXElement(theXElement);
        }

        public static Item Create(MapCell theParent)
        {
            return EntityFactories.Create(theParent, Names.EngineFactories.ItemFactory) as Item;
        }

        public static Item Load(MapCell theParent, XElement theXElement)
        {
            return EntityFactories.Load(theParent, theXElement) as Item;
        }

    }
}
